<?php
jimport('joomla.application.component.model');
class svModelDemo extends JModel
{
	//------------ tim kiem----------------------------------
	function getAllDemo($param)
	{
		$where='';
		$age=JRequest::getInt('age_id');
		$name_id=JRequest::getInt('name_id');
		if($age!=0){ 
			$where=' WHERE age='.$age.'  '; 
			JRequest::setVar('name_id','0');
		}
		if($name_id!=0){
			$where=' WHERE id='.$name_id.'  ';
		}
		$query='SELECT 	 tk.* FROM #__trungkien as tk '.$where.' ORDER BY '.$param['order'].'  '.$param['order_Dir'].'
							LIMIT '.$param['limitstart'].' , '.$param['limit'];
		$result=$this->_loadObjectList($query);
		return $result;
	}
	function getTotal()
	{
		$query='SELECT COUNT(id) FROM #__trungkien';
		$result=$this->_loadResult($query);
		return $result;
	}
	function getParent()
	{
		$query='SELECT DISTINCT age as `key`,age as `text` FROM #__trungkien';
		return $this->_getList($query);
	}
	function getNamelist()
	{
		$where='';
		$age=JRequest::getInt('age_id');
		if($age!=0){
			$where=' WHERE age='.$age.'  ';
		}
		$query='SELECT id as `key`,name as `text` FROM #__trungkien '.$where;
		return $this->_getList($query);
	}
	// xu ly su lieu
	function save()
	{
		JTable::addIncludePath(JPATH_COMPONENT.DS.'tables');
		$demo=JTable::getInstance('demo');
		$demo->bind(JRequest::get('post'));
		$demo->store();
	}
	function remove($id)
	{
		$query='DELETE FROM #__trungkien WHERE id='.$id;
		$this->_Execute($query);
	}
	// cac ham phuc vu truy van CSDL
	function _loadResult($query)
	{
		$db= JFactory::getDBO();
		$db->setQuery($query);
		$result=$db->loadResult();
		return $result;
	}
	function _loadObject($query)
	{
		$db= JFactory::getDBO();
		$db->setQuery($query);
		$result=$db->loadObject();
		return $result;
	}
	function _loadObjectList($query)
	{
		$db= JFactory::getDBO();
		$db->setQuery($query);
		$result=$db->loadObjectList();
		return $result;
	}
	function _Execute($query)
	{
		$db= JFactory::getDBO();
		$db->setQuery($query);
		$db->query();

	}
}
?>